package com.hks360.car_treasure.activity;

import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.hks360.car_treasure.R;
import com.hks360.car_treasure.common.Constant;
import com.hks360.library.nohttp.CallServer;
import com.hks360.library.util.UIUtil;
import com.hks360.library.widget.ILoadingDialog;
import com.umeng.analytics.MobclickAgent;

import java.util.Collection;

import cn.jpush.android.api.JPushInterface;


/**
 * Created by xiaote on 2016/3/11.
 * BaseActivity 初始化Activity 所有的Activity都有继承它
 */
public abstract class BaseActivity extends FragmentActivity implements View.OnClickListener{
    private TextView mTitleTv;
    public ILoadingDialog mDialog;

    /** 初始化控件 */
    public abstract void setupView();
    /** 初始化数据 */
    public abstract void initData();
    /** 添加控件监听器 */
    public abstract void addListener();
    /** 初始化界面 */
    public abstract void initView();
    /** 点击事件触发回调方法 */
    public abstract void viewClick(View v);

    public void initTitleBar(int txtResId) {
        mTitleTv = UIUtil.findViewById(this, R.id.common_title_tv);
        mTitleTv.setText(txtResId);
    }
    public void initTitleBar(String txtResId) {
        mTitleTv = UIUtil.findViewById(this, R.id.common_title_tv);
        mTitleTv.setText(txtResId);
    }

    public void initDialog(int txtResId) {
        mDialog = new ILoadingDialog.Builder(this).setMessage(txtResId).create();
        mDialog.setCancelable(Constant.LOADING_DIALOG_CANCEL);
        mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                CallServer.getRequestInstance().cancelAll();
            }
        });
    }

    public void onClick(View v) {
        viewClick(v);
    }

    public void back(View v) {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //沉浸式状态栏代码
//        然后在布局代码中加入 两行 --> android:fitsSystemWindows="true" android:clipToPadding="true"
//        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//            /** 透明状态栏 */
//            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//            /** 透明导航栏 */
//            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
//        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onResume(this);
    }
}
